package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TransferWorkCountDao;
import com.tianqu.tms.dto.TransferWorkCountDto;

public class TransferWorkCount extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7108736676502071337L;

	private int id;
	private String workType;
	private int workCount;
	private String countDay;
	private int userId;
	private int insertUserId;
	private int updateUserId;

	private String count1;
	private String count2;
	private String count3;
	private String count4;
	private String count5;
	private String count6;
	private String count7;
	private String count8;
	private String count9;
	private String count10;
	private String count11;
	private String count12;
	private String count13;
	private String count14;
	private String count15;
	private String count16;
	private String count17;
	private String count18;
	private String count19;
	private String count20;
	private String count21;
	private String count22;
	private String count23;
	private String count24;
	private String count25;
	private String count26;
	private String count27;
	private String count28;
	private String count29;
	private String count30;
	private String count31;

	private int num;
	private int cssFlag;

	private String groupName;
	private String sum;
	
	private String userName;

	public List<TransferWorkCount> getWorkCountListByMonth(String countMonth,String userId)
			throws TmsDaoException {
		TransferWorkCountDao uDao = (TransferWorkCountDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_WORK_COUNT);
		List<TransferWorkCountDto> dtoList = uDao.getWorkCountListByMonth(countMonth,userId);
		List<TransferWorkCount> list = null;
		// 载入所有用户
		List<TransferWorkCountDto> userList = uDao.getWorkCountUserListByMonth(countMonth,userId);
		
		if (userList != null) {
			list = new ArrayList<TransferWorkCount>();
			int count1 = 0;
			int count2 = 0;
			int count3 = 0;
			int count4 = 0;
			int count5 = 0;
			int count6 = 0;
			int count7 = 0;
			int count8 = 0;
			int count9 = 0;
			int count10 = 0;
			int count11 = 0;
			int count12 = 0;
			int count13 = 0;
			int count14 = 0;
			int count15 = 0;
			int count16 = 0;
			int count17 = 0;
			int count18 = 0;
			int count19 = 0;
			int count20 = 0;
			int count21 = 0;
			int count22 = 0;
			int count23 = 0;
			int count24 = 0;
			int count25 = 0;
			int count26 = 0;
			int count27 = 0;
			int count28 = 0;
			int count29 = 0;
			int count30 = 0;
			int count31 = 0;
			int workType = 0;
			Codes code = Codes.getInstance();
			for (int i = 0; i < userList.size(); i++) {
				TransferWorkCountDto userid = (TransferWorkCountDto) userList.get(i);
				for (int j = 0; j < dtoList.size(); j++) {
					TransferWorkCountDto entity = (TransferWorkCountDto) dtoList.get(j);
					if ((entity.getUserId() == userid.getUserId())&&(entity.getWorkType() == userid.getWorkType())) {
						// 累积
						workType = userid.getWorkType();
						if ("01".equals(entity.getCountDay())) {
							count1 = entity.getWorkCount();
						}
						if ("02".equals(entity.getCountDay())) {
							count2 = entity.getWorkCount();
						}
						if ("03".equals(entity.getCountDay())) {
							count3 = entity.getWorkCount();
						}
						if ("04".equals(entity.getCountDay())) {
							count4 = entity.getWorkCount();
						}
						if ("05".equals(entity.getCountDay())) {
							count5 = entity.getWorkCount();
						}
						if ("06".equals(entity.getCountDay())) {
							count6 = entity.getWorkCount();
						}
						if ("07".equals(entity.getCountDay())) {
							count7 = entity.getWorkCount();
						}
						if ("08".equals(entity.getCountDay())) {
							count8 = entity.getWorkCount();
						}
						if ("09".equals(entity.getCountDay())) {
							count9 = entity.getWorkCount();
						}
						if ("10".equals(entity.getCountDay())) {
							count10 = entity.getWorkCount();
						}
						if ("11".equals(entity.getCountDay())) {
							count11 = entity.getWorkCount();
						}
						if ("12".equals(entity.getCountDay())) {
							count12 = entity.getWorkCount();
						}
						if ("13".equals(entity.getCountDay())) {
							count13 = entity.getWorkCount();
						}
						if ("14".equals(entity.getCountDay())) {
							count14 = entity.getWorkCount();
						}
						if ("15".equals(entity.getCountDay())) {
							count15 = entity.getWorkCount();
						}
						if ("16".equals(entity.getCountDay())) {
							count16 = entity.getWorkCount();
						}
						if ("17".equals(entity.getCountDay())) {
							count17 = entity.getWorkCount();
						}
						if ("18".equals(entity.getCountDay())) {
							count18 = entity.getWorkCount();
						}
						if ("19".equals(entity.getCountDay())) {
							count19 = entity.getWorkCount();
						}
						if ("20".equals(entity.getCountDay())) {
							count20 = entity.getWorkCount();
						}
						if ("21".equals(entity.getCountDay())) {
							count21 = entity.getWorkCount();
						}
						if ("22".equals(entity.getCountDay())) {
							count22 = entity.getWorkCount();
						}
						if ("23".equals(entity.getCountDay())) {
							count23 = entity.getWorkCount();
						}
						if ("24".equals(entity.getCountDay())) {
							count24 = entity.getWorkCount();
						}
						if ("25".equals(entity.getCountDay())) {
							count25 = entity.getWorkCount();
						}
						if ("26".equals(entity.getCountDay())) {
							count26 = entity.getWorkCount();
						}
						if ("27".equals(entity.getCountDay())) {
							count27 = entity.getWorkCount();
						}
						if ("28".equals(entity.getCountDay())) {
							count28 = entity.getWorkCount();
						}
						if ("29".equals(entity.getCountDay())) {
							count29 = entity.getWorkCount();
						}
						if ("30".equals(entity.getCountDay())) {
							count30 = entity.getWorkCount();
						}
						if ("31".equals(entity.getCountDay())) {
							count31 = entity.getWorkCount();
						}

					}
				}

				TransferWorkCount setEntity = new TransferWorkCount();
				setEntity.setCount1(transZ(count1));
				setEntity.setCount2(transZ(count2));
				setEntity.setCount3(transZ(count3));
				setEntity.setCount4(transZ(count4));
				setEntity.setCount5(transZ(count5));
				setEntity.setCount6(transZ(count6));
				setEntity.setCount7(transZ(count7));
				setEntity.setCount8(transZ(count8));
				setEntity.setCount9(transZ(count9));
				setEntity.setCount10(transZ(count10));
				setEntity.setCount11(transZ(count11));
				setEntity.setCount12(transZ(count12));
				setEntity.setCount13(transZ(count13));
				setEntity.setCount14(transZ(count14));
				setEntity.setCount15(transZ(count15));
				setEntity.setCount16(transZ(count16));
				setEntity.setCount17(transZ(count17));
				setEntity.setCount18(transZ(count18));
				setEntity.setCount19(transZ(count19));
				setEntity.setCount20(transZ(count20));
				setEntity.setCount21(transZ(count21));
				setEntity.setCount22(transZ(count22));
				setEntity.setCount23(transZ(count23));
				setEntity.setCount24(transZ(count24));
				setEntity.setCount25(transZ(count25));
				setEntity.setCount26(transZ(count26));
				setEntity.setCount27(transZ(count27));
				setEntity.setCount28(transZ(count28));
				setEntity.setCount29(transZ(count29));
				setEntity.setCount30(transZ(count30));
				setEntity.setCount31(transZ(count31));
				if (i % 2 == 0) {
					setEntity.setCssFlag(1);
				} else {
					setEntity.setCssFlag(2);
				}
				setEntity.setWorkType(code.getItemValueByItemIdAndItemCode(
						Codes.WORK_TYPE, workType));
				setEntity.setNum(i + 1);
				User user = new User();
				user = user.getUserInfoById(userid.getUserId());
				setEntity.setUserName(user.getRealName());
//				// 根据role获取部门名
//				UserAuth auth = new UserAuth();
//				boolean zz = auth
//						.getAuthInfoByRole(userid.getUserId(), 510);
//				if (zz) {
//					setEntity.setGroupName("制证部");
//				}
//				boolean sl = auth
//						.getAuthInfoByRole(userid.getUserId(), 500);
//				if (sl) {
//					setEntity.setGroupName("受理部");
//				}
				TransferWorkCountDto sumDto = uDao.getSumByUserIdAndMonth(countMonth,userid.getUserId(),userid.getWorkType()); 
				setEntity.setSum(transZ(sumDto.getWorkCount()));
				setEntity.setUserId(userid.getUserId());
				list.add(setEntity);
				count1 = 0;
				count2 = 0;
				count3 = 0;
				count4 = 0;
				count5 = 0;
				count6 = 0;
				count7 = 0;
				count8 = 0;
				count9 = 0;
				count10 = 0;
				count11 = 0;
				count12 = 0;
				count13 = 0;
				count14 = 0;
				count15 = 0;
				count16 = 0;
				count17 = 0;
				count18 = 0;
				count19 = 0;
				count20 = 0;
				count21 = 0;
				count22 = 0;
				count23 = 0;
				count24 = 0;
				count25 = 0;
				count26 = 0;
				count27 = 0;
				count28 = 0;
				count29 = 0;
				count30 = 0;
				count31 = 0;
				workType = 0;
			}
		}
		return list;
	}

	private String transZ(int z)
	{
		if(z==0)
		{
			return "";
		}
		return String.valueOf(z);
	}
	
	public TransferWorkCount getTransferWorkCountByIdAndTime(String workType,String userid,String time)throws TmsDaoException
	{
		TransferWorkCountDao uDao = (TransferWorkCountDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_WORK_COUNT);
		TransferWorkCountDto dto = uDao.getTransferWorkCountByIdAndTime(workType,Integer.parseInt(userid),time);
		TransferWorkCount entity = null;
		if(dto!=null)
		{
			entity = new TransferWorkCount();
			entity.setWorkType(String.valueOf(dto.getWorkType()));
			entity.setWorkCount(dto.getWorkCount());
			entity.setCountDay(dto.getCountDay());
			entity.setUserId(dto.getUserId());
		}
		return entity;
	}
	public void insertTransferWorkCountInfo(TransferWorkCount entity)throws TmsDaoException
	{
		TransferWorkCountDao uDao = (TransferWorkCountDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_WORK_COUNT);
		TransferWorkCountDto dto = new TransferWorkCountDto();
		dto.setWorkType(Integer.parseInt(entity.getWorkType()));
		dto.setWorkCount(entity.getWorkCount());
		dto.setCountDayTamp(DateUtil.getStringToTimeStamp1(entity.getCountDay()+" 00:00:00"));
		dto.setUserId(entity.getUserId());
		dto.setInsertUserId(entity.getInsertUserId());
		uDao.insertTransferWorkCountInfo(dto);
	}
	
	public void updateTransferWorkCountInfo(TransferWorkCount entity)throws TmsDaoException
	{
		TransferWorkCountDao uDao = (TransferWorkCountDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_WORK_COUNT);	
		TransferWorkCountDto dto = new TransferWorkCountDto();
		dto.setWorkType(Integer.parseInt(entity.getWorkType()));
		dto.setWorkCount(entity.getWorkCount());
		dto.setCountDay(entity.getCountDay());
		dto.setUserId(entity.getUserId());
		dto.setUpdateUserId(entity.getUpdateUserId());
		uDao.updateTransferWorkCountInfo(dto);
	}
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getWorkType() {
		return workType;
	}

	public void setWorkType(String workType) {
		this.workType = workType;
	}

	public int getWorkCount() {
		return workCount;
	}

	public void setWorkCount(int workCount) {
		this.workCount = workCount;
	}

	public String getCountDay() {
		return countDay;
	}

	public void setCountDay(String countDay) {
		this.countDay = countDay;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public int getInsertUserId() {
		return insertUserId;
	}

	public void setInsertUserId(int insertUserId) {
		this.insertUserId = insertUserId;
	}

	public int getUpdateUserId() {
		return updateUserId;
	}

	public void setUpdateUserId(int updateUserId) {
		this.updateUserId = updateUserId;
	}

	public String getCount1() {
		return count1;
	}

	public void setCount1(String count1) {
		this.count1 = count1;
	}

	public String getCount2() {
		return count2;
	}

	public void setCount2(String count2) {
		this.count2 = count2;
	}

	public String getCount3() {
		return count3;
	}

	public void setCount3(String count3) {
		this.count3 = count3;
	}

	public String getCount4() {
		return count4;
	}

	public void setCount4(String count4) {
		this.count4 = count4;
	}

	public String getCount5() {
		return count5;
	}

	public void setCount5(String count5) {
		this.count5 = count5;
	}

	public String getCount6() {
		return count6;
	}

	public void setCount6(String count6) {
		this.count6 = count6;
	}

	public String getCount7() {
		return count7;
	}

	public void setCount7(String count7) {
		this.count7 = count7;
	}

	public String getCount8() {
		return count8;
	}

	public void setCount8(String count8) {
		this.count8 = count8;
	}

	public String getCount9() {
		return count9;
	}

	public void setCount9(String count9) {
		this.count9 = count9;
	}

	public String getCount10() {
		return count10;
	}

	public void setCount10(String count10) {
		this.count10 = count10;
	}

	public String getCount11() {
		return count11;
	}

	public void setCount11(String count11) {
		this.count11 = count11;
	}

	public String getCount12() {
		return count12;
	}

	public void setCount12(String count12) {
		this.count12 = count12;
	}

	public String getCount13() {
		return count13;
	}

	public void setCount13(String count13) {
		this.count13 = count13;
	}

	public String getCount14() {
		return count14;
	}

	public void setCount14(String count14) {
		this.count14 = count14;
	}

	public String getCount15() {
		return count15;
	}

	public void setCount15(String count15) {
		this.count15 = count15;
	}

	public String getCount16() {
		return count16;
	}

	public void setCount16(String count16) {
		this.count16 = count16;
	}

	public String getCount17() {
		return count17;
	}

	public void setCount17(String count17) {
		this.count17 = count17;
	}

	public String getCount18() {
		return count18;
	}

	public void setCount18(String count18) {
		this.count18 = count18;
	}

	public String getCount19() {
		return count19;
	}

	public void setCount19(String count19) {
		this.count19 = count19;
	}

	public String getCount20() {
		return count20;
	}

	public void setCount20(String count20) {
		this.count20 = count20;
	}

	public String getCount21() {
		return count21;
	}

	public void setCount21(String count21) {
		this.count21 = count21;
	}

	public String getCount22() {
		return count22;
	}

	public void setCount22(String count22) {
		this.count22 = count22;
	}

	public String getCount23() {
		return count23;
	}

	public void setCount23(String count23) {
		this.count23 = count23;
	}

	public String getCount24() {
		return count24;
	}

	public void setCount24(String count24) {
		this.count24 = count24;
	}

	public String getCount25() {
		return count25;
	}

	public void setCount25(String count25) {
		this.count25 = count25;
	}

	public String getCount26() {
		return count26;
	}

	public void setCount26(String count26) {
		this.count26 = count26;
	}

	public String getCount27() {
		return count27;
	}

	public void setCount27(String count27) {
		this.count27 = count27;
	}

	public String getCount28() {
		return count28;
	}

	public void setCount28(String count28) {
		this.count28 = count28;
	}

	public String getCount29() {
		return count29;
	}

	public void setCount29(String count29) {
		this.count29 = count29;
	}

	public String getCount30() {
		return count30;
	}

	public void setCount30(String count30) {
		this.count30 = count30;
	}

	public String getCount31() {
		return count31;
	}

	public void setCount31(String count31) {
		this.count31 = count31;
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getCssFlag() {
		return cssFlag;
	}

	public void setCssFlag(int cssFlag) {
		this.cssFlag = cssFlag;
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public String getSum() {
		return sum;
	}

	public void setSum(String sum) {
		this.sum = sum;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

}
